package com.yzjs.common.export;

import com.yzjs.common.base.entity.AbstractBasePojo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

public abstract class AbstractExport<T extends AbstractBasePojo> {
    protected final Logger logger = LoggerFactory.getLogger(getClass());

    private static final int PAGE_SIZE = 1000;

    private static final int PROGRESS_ROW_COUNT = 10000;

    protected String charset = "UTF-8";

    protected String fileName;

    protected String[] headerNames;

    protected String[] colNames;

    private List<String> headerNameList = new ArrayList<>();

    private List<String> colNameList = new ArrayList<>();

    public AbstractExport() {
        config();
    }

    protected void addColInfo(String header, String colName) {
        this.headerNameList.add(header);
        this.colNameList.add(colName);
    }

    public void printCoventCode() {
        for (int i = 0; i < this.headerNames.length; i++)
            System.out.println("this.addColInfo(\"" + this.headerNames[i] + "\", \"" + this.colNames[i] + "\");");
        System.out.println("this.setColInfo();");
    }

    protected void setColInfo() {
        this.headerNames = this.headerNameList.<String>toArray(new String[this.headerNameList.size()]);
        this.colNames = this.colNameList.<String>toArray(new String[this.colNameList.size()]);
    }

    protected abstract void config();

    protected abstract List<?> getDataList(T paramT);

    protected abstract Object getObjVal(String paramString, Object paramObject, Map<String, Object> paramMap);

    public abstract String export(Date paramDate, String paramString, T paramT, IExportProgress paramIExportProgress);

    protected static int getPageSize() {
        return 1000;
    }

    public static int getProgressRowCount() {
        return 10000;
    }

    public String getFileName() {
        return this.fileName;
    }

    public String[] getHeaderNames() {
        return this.headerNames;
    }

    public String[] getColNames() {
        return this.colNames;
    }
}